package com.yami.shop.user.api.controller;

import com.yami.shop.bean.app.dto.ProductDto;
import com.yami.shop.bean.enums.ProdType;
import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.i18n.I18nMessage;
import com.yami.shop.service.ProductService;
import com.yami.shop.service.SkuService;
import com.yami.shop.user.comment.service.UserLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */


@RestController
@RequestMapping("/score/prod")
@Api(tags = "积分商品接口")
public class ScoreProdController {

    @Autowired
    private ProductService prodService;

    @Autowired
    private MapperFacade mapperFacade;

    @Autowired
    private SkuService skuService;

    @Autowired
    private UserLevelService userLevelService;





//    @GetMapping("/prodInfo")
//    @ApiOperation(value = "积分商品详情信息", notes = "根据商品ID（prodId）获取商品信息")
//    @ApiImplicitParam(name = "prodId", value = "商品ID", required = true, dataType = "Long")
//    public ResponseEntity<ProductDto> prodInfo(Long prodId) {
//
//        Product product = prodService.getProductByProdId(prodId, I18nMessage.getDbLang());
//        if (product == null || product.getStatus() != 1) {
//            //商品已下线
//            throw new YamiShopBindException("yami.product.off.shelves");
//        }
//        if (!Objects.equals(product.getProdType(), ProdType.PROD_TYPE_SCORE.value()) || product.getScorePrice() <= 0) {
//            // 不是积分商品或者积分价格异常
//            throw new YamiShopBindException("yami.user.score.prod");
//        }
//
//        List<Sku> skuList = skuService.listByProdId(prodId, I18nMessage.getDbLang());
//        // 启用的sku列表
//        List<Sku> useSkuList = skuList.stream().filter(sku -> sku.getStatus() == 1).collect(Collectors.toList());
//        product.setSkuList(useSkuList);
//        ProductDto productDto = mapperFacade.map(product, ProductDto.class);
//        return ResponseEntity.ok(productDto);
//    }




}
